package com.itheima.filter;


import jakarta.servlet.*;

import java.io.IOException;


//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    @Override    // init方法在Filter被加载时调用，只会被执行一次

    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化方法执行了");
    }

    @Override       // doFilter方法在每次请求时被调用，可以对请求进行处理
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        System.out.println("Demo 拦截到了请求...放行前逻辑");
        // 调用FilterChain的doFilter方法，让请求继续向下执行
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("DemoFilter   放行后逻辑.....");

    }

    @Override     // destroy方法在Filter被卸载时调用，只会被执行一次
    public void destroy() {
        System.out.println("destroy 销毁方法执行了");
    }
}
